import { ElMessage, ElMessageBox } from 'element-plus'
export const duration = 2000

export const successMes = (title) => {
  ElMessage({
    duration: duration,
    showClose: true,
    message: title,
    type: 'success',
  })
}
export const warningMes = (title) => {
  ElMessage({
    duration: duration,
    showClose: true,
    message: title,
    type: 'warning',
  })
}
export const errorMes = (title) => {
  ElMessage({
    duration: duration,
    showClose: true,
    message: title,
    type: 'error',
  })
}
export const inforMes = (title) => {
  ElMessage({
    duration: duration,
    showClose: true,
    message: title,
  })
}
export const messageboxMes = (title, type) => {
  return new Promise((resolve, reject) => {
    ElMessageBox.confirm(title, type, {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
    })
      .then(() => {
        resolve(true)
      })
      .catch(() => {
        reject(false)
      })
  })
}
export const SetLocal = (key, val) => {
  localStorage.setItem(key, val)
}

export const GetLocal = (key, val) => {
  return localStorage.getItem(key)
}

export const DeleteLocal = (key) => {
  localStorage.removeItem(key)
}

export default {
  install(app) {
    app.config.globalProperties.$successMes = successMes
    app.config.globalProperties.$warningMes = warningMes
    app.config.globalProperties.$errorMes = errorMes
    app.config.globalProperties.$inforMes = inforMes
    app.config.globalProperties.$messageboxMes = messageboxMes
    app.config.globalProperties.$SetLocal = SetLocal
    app.config.globalProperties.$GetLocal = GetLocal
    app.config.globalProperties.$DeleteLocal = DeleteLocal
  },
}
